$(function(){
    $("#yqysk_toolbar input[name='startDate']").datebox();
    $("#yqysk_toolbar input[name='endDate']").datebox();
    $("#yqysk_toolbar input[name='gsId']").jgbmtree($("#yqysk_toolbar input[name='bmId']"),undefined,$("#yqysk_toolbar input[name='bmId']").val(),undefined);
//    $("#yqysk_toolbar [name='gsId']").gsjgtree(1);
    //搜索按钮
    $("#yqysk_toolbar [name='searchButton']").click(function () {
        $(grid).datagrid({
            queryParams: {
                startDate: $("#yqysk_toolbar [name='startDate']").val(),
                endDate: $("#yqysk_toolbar [name='endDate']").val(),
                gsId: $("#yqysk_toolbar [name='gsId']").val(),
                bmId: $("#yqysk_toolbar [name='bmId']").val()
            }});
    });

    var columns = [
        [
//            {field:'id',title:'单号',width:30,rowspan:2,align:'center'},
//            {field:'gsmc',title:'分公司',width:100,rowspan:2,align:'center'},
            {field:'khmc',title:'回款客户',width:100,rowspan:2,align:'center'},
            {title:'应收款(单位：元)',colspan:3},
            {title:'应收款分期分布情况',colspan:5}
        ],
        [
            {field: 'wq', title: '应收款上期', width: 60,align:'right'},
            {field: 'bq', title: '应收款本期', width: 60,align:'right'},
            {field: 'yskxj', title: '应收款小计', width: 60,align:'right'},
            {field: 'm12', title: '1个月以上', width: 60,align:'right'},
            {field: 'm23', title: '2个月以上', width: 60,align:'right'},
            {field: 'm36', title: '3个月以上', width: 60,align:'right'},
            {field: 'hy', title: '半年以上', width: 60,align:'right'},
            {field: 'y', title: '一年以上', width: 60,align:'right'}
        ]
    ];

    var grid = $('#yqysk_datagrid').datagrid({
        url: $.webPath() + '/report/yqysk/yqyskList',
        toolbar: "#yqysk_toolbar",
        rownumbers: true,
        singleSelect: true,
        fit: true,
        fitColumns: true,
        pageNumber: 1,
        showFooter: true,
        queryParams: {
            startDate: $("#yqysk_toolbar [name='startDate']").val(),
            endDate: $("#yqysk_toolbar [name='endDate']").val()
        },
        columns: columns,
        view:groupview,
        groupField:'gsid',
        groupFormatter:function(value,rows){
            return '分公司:'+rows[0].gsmc+ ' - ' + rows.length + ' 条记录';
        }
    });

});